/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sqlgenerators.search;

import entities.Search;

/**
 *
 * @author damfercer
 */
public class PersonalSQLGenerator implements SearchSqlGeneratorInterface{
    private String sqlRes;
    @Override
    public String getSqlFromSearch(Search search) {
        sqlRes="";
        if(search.getResidenceCountry()!=null){
            sqlRes+=" AND candidate.COUNTRY="+search.getResidenceCountry().getIdCountry();
        }
        if(search.getResidenceProvince()!=null){
            sqlRes+=" AND candidate.PROVINCE="+search.getResidenceProvince().getIdProvince();
        }
        if(search.getResidenceTown()!=null){
            sqlRes+=" AND candidate.TOWN="+search.getResidenceTown().getIdTown();
        }
        if(search.getMinimumTimeAvailability()!=null){
            //cambiar más adelante para afinar más
            int value=search.getMinimumTimeAvailability().getValue();
            sqlRes+=" AND (candidate.TIME_AVAILABILITY="+search.getMinimumTimeAvailability().getIdTimeAvailability()+" OR time_availability.VALUE>"+value+")";
            
        }
        if(search.getRequiredVehicle()!=null && search.getRequiredVehicle()){
            sqlRes+=" AND candidate.HAS_VEHICLE=1";
        }
        return sqlRes;
    }
    
}
